//导入request.js工具类
import request from '@/utils/request.js'

//注册接口
export const userRegisterService = (registerData) => {
    //由于registerData是一个application/x-www-form-urlencoded格式的数据，所以我们需要将其转换为json字符串
    //使用UrlSearchParams对象来处理URL参数即？后面的部分
    const params = new URLSearchParams()
    for (let key in registerData) {
        params.append(key, registerData[key])
    }
    return request.post('/user/register', params)
}
//登录接口，成功后后端返回token
export const userLoginService = (loginData) => {
    const params = new URLSearchParams()
    for (let key in loginData) {
        params.append(key, loginData[key])
    }
    return request.post('/user/login', params)
}
//获取用户信息接口
export const userInfoService = () => {
    return request.get('/user/userInfo')
}
//更新用户信息接口
export const userInfoUpdateService = (userInfoData) => {
    return request.put('/user/update', userInfoData)
}
//修改用户头像接口
export const userAvatarUpdateService = (avatarUrl) => {
    const params = new URLSearchParams()
    params.append('avatarUrl', avatarUrl)
    return request.patch('/user/updateAvatar', params)
}
// 修改用户密码接口
export const userPasswordUpdateService = (passwordData, token) => {
    return request.patch('/user/updatePassword', passwordData, {
        headers: {
            'Content-Type': 'application/json',
            'Authorization': token
        }
    });
};